class Api::ColumnsController < ApplicationController
  before_action :set_column, only: [:show, :update, :destroy]

  def index
    @result = {}
    @result[:total] = Column.filt(params[:filter]).size
    @result[:data] = Column.filt(params[:filter]).sort(params[:sort]).page(params[:page]).per(params[:limit])
    render json: @result
  end

  def show
    render json: @column
  end

  def create
    @column = Column.new(column_params)
    if @column.save
      render json: { success: true }
    else
      render json: { success: false }
    end
  end

  def update
    @column.update(column_params)
    render json: { success: true }
  end

  def destroy
    @column.destroy
    render json: { success: true }
  end

  private

  def set_column
    @column = Column.find(params[:id])
  end

  def column_params
    params.require(:column).permit(:name, :text, :genre, :editable, :hidden, :width, :align, :model_id)
  end
end